package com.mms.utsc.smartnet;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Announcement {

	public enum AnnouncementType {
		REMINDER, ACADEMIC, JOBS, FINANCIAL, ACADEMIC_SUPPORT, RESEARCH, NEWS, COMMUNITY, ADMINISTRATIVE;
	}

	private static Map<AnnouncementType, String> typeStrConvert = new HashMap<AnnouncementType, String>();
	private static boolean initializedMap = false;

	Date date;
	Date expireDate;
	String titleText;
	String content;
	AnnouncementType type;
	int ID;
	//user can mark announcements as important
	boolean important;

	public Announcement(int ID, Date date, Date expireDate, String titleText, String content, AnnouncementType type, boolean important) {
		// TODO*****
		//string to date conversion
		this.ID = ID;
		this.date = date;
		this.expireDate = expireDate;
		this.titleText = titleText;
		this.content = content;
		this.type = type;
		this.important = important;
		if (!Announcement.initializedMap) {
			typeStrConvert.put(AnnouncementType.REMINDER, "Reminder");
			typeStrConvert.put(AnnouncementType.ACADEMIC, "Academic");
			typeStrConvert.put(AnnouncementType.JOBS, "Employment");
			typeStrConvert.put(AnnouncementType.FINANCIAL, "Financial and Registration");
			typeStrConvert.put(AnnouncementType.ACADEMIC_SUPPORT, "Academic Support");
			typeStrConvert.put(AnnouncementType.RESEARCH, "Research");
			typeStrConvert.put(AnnouncementType.NEWS, "News");
			typeStrConvert.put(AnnouncementType.COMMUNITY, "Community");
			typeStrConvert.put(AnnouncementType.ADMINISTRATIVE, "Administrative");
			Announcement.initializedMap = true;
		}
	}

	Date getDate() {
		return date;
	}

	Date getExpireDate() {
		return expireDate;
	}

	String getTitleText() {
		return titleText;
	}

	String getContent() {
		return content;
	}

	AnnouncementType getType() {
		return type;
	}

	String getTypeStr() {
		return Announcement.convertTypeToStr(this.getType());
	}

	int getID() {
		return ID;
	}
	
	boolean isImportant(){
		return important;
	}
	
	void setIsImportant(boolean important){
		this.important = important;
	}

	static String convertTypeToStr(AnnouncementType type) {
		return Announcement.typeStrConvert.get(type);
	}

	static ArrayList<Announcement> filterType(ArrayList<Announcement> input, AnnouncementType type) {
		ArrayList<Announcement> temp = new ArrayList<Announcement>();
		for (int index = 0; index < input.size(); index++) {
			if (input.get(index).getType() == type) {
				temp.add(input.get(index));
			}
		}

		if (temp.size() == 0) {
			return null;
		}

		return temp;
	}
}
